function [mean_RM, mean_PV, RM_rotation, PV_rotation, ER_correlation, Mean_Event_Rate, Cell_Recurring_Probability, MI_and_pMI, RM_correlation, Shuffled_RM_correlation, PV_correlation, Shuffled_PV_correlation, Active_Cell_Proportion, Mobility, Event_Rate] = Make_Tables_for_STAT(Data_Summary, Placeness_MetaData)

% this funtion aims to summarize analysis results into tables for further
% statistical tests & graphing

%% Cell Recurring Probability
Cell_Recurring_Prob_structure = [];
for n = 1:size(Data_Summary,2)
    if isempty(Cell_Recurring_Prob_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        Cell_Recurring_Prob_structure = Pull_Out_Cell_Recurring_Probability(Data_Summary, n);
    elseif ~isempty(Cell_Recurring_Prob_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        S = Pull_Out_Cell_Recurring_Probability(Data_Summary, n);
        Cell_Recurring_Prob_structure = cat(1, Cell_Recurring_Prob_structure, S);
    end
end
Cell_Recurring_Probability = struct2table(Cell_Recurring_Prob_structure);

%% MI values & its p values based on shuffle test
MI_structure = [];
for n = 1:size(Placeness_MetaData,2)
    if isempty(MI_structure) && Placeness_MetaData(n).Mobility_Pass == 1
        MI_structure = Pull_Out_MI_Single_Session(Placeness_MetaData, n);
    elseif ~isempty(MI_structure) && Placeness_MetaData(n).Mobility_Pass == 1
        S = Pull_Out_MI_Single_Session(Placeness_MetaData, n);
        MI_structure = cat(1, MI_structure, S);
    end
end
MI_and_pMI = struct2table(MI_structure);

%% RM values
RM_structure = [];
for n = 1:size(Data_Summary,2)
    if isempty(RM_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [RM_structure] = Pull_Out_RM_Single_Session(Data_Summary, n);
    elseif ~isempty(RM_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [S] = Pull_Out_RM_Single_Session(Data_Summary, n);
        RM_structure = cat(1, RM_structure, S);
    end
end
RM_correlation = struct2table(RM_structure);

%% RM shuffled values
Shuffled_RM_structure = [];
for n = 1:size(Data_Summary,2)
    if isempty(Shuffled_RM_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [Shuffled_RM_structure] = Pull_Out_Shuffled_RM_Single_Session(Data_Summary, n);
    elseif ~isempty(Shuffled_RM_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [S] = Pull_Out_Shuffled_RM_Single_Session(Data_Summary, n);
        Shuffled_RM_structure = cat(1, Shuffled_RM_structure, S);
    end
end
Shuffled_RM_correlation = struct2table(Shuffled_RM_structure);

%% Mean RM
mean_RM_structure = [];
for n = 1:size(Data_Summary,2)
    if isempty(mean_RM_structure)
        [mean_RM_structure] = Pull_Out_mean_RM(Data_Summary, n);
    elseif ~isempty(mean_RM_structure)
        [S] = Pull_Out_mean_RM(Data_Summary, n);
        mean_RM_structure = cat(1, mean_RM_structure, S);
    end
end
mean_RM = struct2table(mean_RM_structure);

%% PV values
PV_structure = [];
for n = 1:size(Data_Summary,2) 
    if isempty(PV_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [PV_structure] = Pull_Out_PV_Single_Session(Data_Summary, n);
    elseif ~isempty(PV_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [S] = Pull_Out_PV_Single_Session(Data_Summary, n);
        PV_structure = cat(1, PV_structure, S);
    end
end
PV_correlation = struct2table(PV_structure);

%% PV shuffled values
Shuffled_PV_structure = [];
for n = 1:size(Data_Summary,2) 
    if isempty(Shuffled_PV_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [Shuffled_PV_structure] = Pull_Out_Shuffled_PV_Single_Session(Data_Summary, n);
    elseif ~isempty(Shuffled_PV_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [S] = Pull_Out_Shuffled_PV_Single_Session(Data_Summary, n);
        Shuffled_PV_structure = cat(1, Shuffled_PV_structure, S);
    end
end
Shuffled_PV_correlation = struct2table(Shuffled_PV_structure);

%% Mean PV
mean_PV_structure = [];
for n = 1:size(Data_Summary,2)
    if isempty(mean_PV_structure)
        [mean_PV_structure] = Pull_Out_mean_PV(Data_Summary, n);
    elseif ~isempty(mean_PV_structure)
        [S] = Pull_Out_mean_PV(Data_Summary, n);
        mean_PV_structure = cat(1, mean_PV_structure, S);
    end
end
mean_PV = struct2table(mean_PV_structure);

%% Active Cell Proportion (Both, session1 only, session2 only)
Active_Cell_Proportion_Structure = [];
for n = 1:size(Data_Summary,2) 
    if isempty(Active_Cell_Proportion_Structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [Active_Cell_Proportion_Structure] = Pull_Out_Active_Cell_Proportion(Data_Summary, n);
    elseif ~isempty(Active_Cell_Proportion_Structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [S] = Pull_Out_Active_Cell_Proportion(Data_Summary, n);
        Active_Cell_Proportion_Structure = cat(1, Active_Cell_Proportion_Structure, S);
    end
end
Active_Cell_Proportion = struct2table(Active_Cell_Proportion_Structure);

%% Mobility
Mobility_structure = [];
for n = 1:size(Data_Summary,2)
    if isempty(Mobility_structure)
        [Mobility_structure] = Pull_Out_Mobility(Data_Summary, n);
    elseif ~isempty(Mobility_structure)
        [S] = Pull_Out_Mobility(Data_Summary, n);
        Mobility_structure = cat(1, Mobility_structure, S);
    end
end
Mobility = struct2table(Mobility_structure);

%% Event Rate
Event_Rate_structure = [];
for n = 1:size(Data_Summary,2)
    if isempty(Event_Rate_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [Event_Rate_structure] = Pull_Out_Event_Rate(Data_Summary, n);
    elseif ~isempty(Event_Rate_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [S] = Pull_Out_Event_Rate(Data_Summary, n);
        Event_Rate_structure = cat(1, Event_Rate_structure, S);
    end
end
Event_Rate = struct2table(Event_Rate_structure);

%% Mean Event Rate
Mean_Event_Rate_structure = [];
for n = 1:size(Data_Summary,2) 
    if isempty(Mean_Event_Rate_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [Mean_Event_Rate_structure] = Pull_Out_Mean_Event_Rate(Data_Summary, n);
    elseif ~isempty(Mean_Event_Rate_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [S] = Pull_Out_Mean_Event_Rate(Data_Summary, n);
        Mean_Event_Rate_structure = cat(1, Mean_Event_Rate_structure, S);
    end
end
Mean_Event_Rate = struct2table(Mean_Event_Rate_structure);

%% Event rate correlation
Event_Rate_Correlation_Structure = [];
for n = 1:size(Data_Summary,2) 
    if isempty(Event_Rate_Correlation_Structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [Event_Rate_Correlation_Structure] = Pull_Out_Event_Rate_Correlation(Data_Summary, n);
    elseif ~isempty(Event_Rate_Correlation_Structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [S] = Pull_Out_Event_Rate_Correlation(Data_Summary, n);
        Event_Rate_Correlation_Structure = cat(1, Event_Rate_Correlation_Structure, S);
    end
end
ER_correlation = struct2table(Event_Rate_Correlation_Structure);

%% PV Rotation
PV_Rotation_structure = [];
for n = 1:size(Data_Summary,2)
    if isempty(PV_Rotation_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [PV_Rotation_structure] = Pull_Out_PV_Rotation(Data_Summary, n);
    elseif ~isempty(PV_Rotation_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [S] = Pull_Out_PV_Rotation(Data_Summary, n);
        PV_Rotation_structure = cat(1, PV_Rotation_structure, S);
    end
end
PV_rotation = struct2table(PV_Rotation_structure);

%% RM Rotation
RM_Rotation_structure = [];
for n = 1:size(Data_Summary,2)
    if isempty(RM_Rotation_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [RM_Rotation_structure] = Pull_Out_RM_Rotation(Data_Summary, n);
    elseif ~isempty(RM_Rotation_structure) && Data_Summary(n).Mobility_Session1_Pass == 1
        [S] = Pull_Out_RM_Rotation(Data_Summary, n);
        RM_Rotation_structure = cat(1, RM_Rotation_structure, S);
    end
end
RM_rotation = struct2table(RM_Rotation_structure);

end